//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.mingsoft.basic.action.web;

import io.swagger.annotations.ApiOperation;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.mingsoft.base.action.BaseAction;
import net.mingsoft.basic.biz.IAppBiz;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.SpringUtil;
import net.mingsoft.config.MSProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@Controller("indexAction")
public class IndexAction extends BaseAction {
    private static String INDEX = "index.html";
    private static String DEFAULT = "default.html";
    private IAppBiz appBiz;

    public IndexAction() {
    }

    @ApiOperation("访问站点主页")
    @GetMapping({"/msIndex"})
    public String index(HttpServletRequest req, HttpServletResponse res) throws IOException {
        String htmlDir = MSProperties.diy.htmlDir;
        this.LOG.debug("basic index");
        this.appBiz = (IAppBiz)SpringUtil.getBean(IAppBiz.class);
        String dir = "";
        AppEntity website = BasicUtil.getApp();
        if (website != null) {
            dir = StringUtils.isNotBlank(website.getAppDir()) ? website.getAppDir() : "";
            String defaultHtmlPath = BasicUtil.getRealPath(htmlDir + File.separator + dir + File.separator + DEFAULT);
            this.LOG.debug("defaultHtmlPath {}", defaultHtmlPath);
            File file = new File(defaultHtmlPath);
            String url = htmlDir + "/" + dir;
            String indexPosition = url + "/" + INDEX;
            if (file.exists()) {
                indexPosition = url + "/" + DEFAULT;
            }

            this.LOG.debug("indexPosition {}", indexPosition);
            return "forward:" + indexPosition;
        } else {
            return "";
        }
    }
}
